package com.glodon.paas.document.storage.service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.document.storage.dao.mapper.AuditMapper;

@Service
public class AuditService {
    @Autowired
    private AuditMapper auditMapper;

    public void addAudit(String objectId, String auditType, Date updateTime) {
        auditMapper.insertObject(objectId, auditType, updateTime);
    }

    public List<String> getAuditObjectId(String auditType, Date date) {
        Calendar startCal = Calendar.getInstance();
        startCal.setTime(date);
        startCal.set(Calendar.HOUR_OF_DAY, 0);
        startCal.set(Calendar.MINUTE, 0);
        startCal.set(Calendar.SECOND, 0);
        Calendar endCal = Calendar.getInstance();
        endCal.setTime(date);
        endCal.set(Calendar.HOUR_OF_DAY, 24);
        endCal.set(Calendar.MINUTE, 0);
        endCal.set(Calendar.SECOND, 0);
        return auditMapper.getAuditObjectId(auditType, startCal.getTime(), endCal.getTime());
    }

    public void setAuditMapper(AuditMapper auditMapper) {
        this.auditMapper = auditMapper;
    }
}
